Imports System.Reflection

Namespace BusinessLogicLayer

    Public Class Globals
        Public Enum UserProperties
            UserID
            UserName
            LastLogin
            MainFilter
            TaskFilter
        End Enum

        Public Enum DataBaseBackUp
            DataBaseExists
            DataBaseBackedUp
            DataBaseError
        End Enum

        Public Enum ReportDisplay
            AddToOther = 1
            DontDisplay = 2
            Display = 3
        End Enum

        Public Enum RIBSState
            Allocated
            Unallocated
            Pending
            Closed
        End Enum

        Public Shared Function StateAllocated() As String
            Return "Allocated"
        End Function

        Public Shared Function StateOther() As String
            Return "Other"
        End Function

        Public Shared Function StateUnallocated() As String
            Return "Unallocated"
        End Function

        Public Shared Function GetPropertiesAsDT(ByRef obj As Type, ByVal TableName As String) As DataTable
            Try
                Dim dt As New DataTable(TableName)
                Dim myProperties() As PropertyInfo = _
                  obj.GetProperties((BindingFlags.Public Or BindingFlags.Instance))

                For Each PropertyItem As PropertyInfo In myProperties
                    dt.Columns.Add(PropertyItem.Name, Type.GetType(PropertyItem.PropertyType.ToString))
                Next
                Return dt
            Catch ex As Exception
                Throw ex
            End Try

        End Function

        Public Shared Function dbDateFormat(ByVal dDate As Date) As String
            Try
                Dim rtStr As String = "#" & Microsoft.VisualBasic.Day(dDate) & " " & MonthName(Month(dDate)) & " " & Year(dDate) & "#"
                Return rtStr
            Catch ex As Exception
                Throw ex
            End Try
        End Function

        Public Shared Function ReportContactMethodDisplayName(ByVal dbName As String) As String
            Try
                Select Case dbName
                    Case "Adviser Incoming Phone"
                        Return "FA In"
                    Case "Adviser Outgoing  Phone"
                        Return "FA Out"
                    Case "Adviser In-Email"
                        Return "FA E-Mail"
                    Case "Adviser In-Mail"
                        Return "FA Mail"
                    Case "Client Incoming Phone"
                        Return "Client In"
                    Case "Client Outgoing  Phone"
                        Return "Client Out"
                    Case "Client In-Email"
                        Return "Client E-mail"
                    Case "Client In-Mail"
                        Return "Client Mail"
                    Case "Other"
                        Return "Other"
                    Case "NAR (No Action Required)"
                        Return "NAR"
                    Case "Unallocated"
                        Return ""
                    Case "Outgoing E-mail"
                        Return ""
                    Case "Outgoing Mail"
                        Return ""
                End Select
            Catch ex As Exception
                Throw ex
            End Try
            Return ""
        End Function

        Public Shared Function ReportContactMethods() As String()
            Try
                Dim answers As Boolean() = New Boolean() {True, True, False, True}

                Dim ContactMethods As String() = New String() _
                                           {"Adviser Incoming Phone", _
                                            "Adviser In-Email", _
                                            "Adviser In-Mail", _
                                            "Adviser Outgoing  Phone", _
                                            "Client Incoming Phone", _
                                            "Client Outgoing  Phone", _
                                            "Client In-Email", _
                                            "Client In-Mail", _
                                            "Other", _
                                            "Outgoing E-mail", _
                                            "Outgoing Mail", _
                                            "NAR (No Action Required)", _
                                            "Unallocated"}
                Return ContactMethods
            Catch ex As Exception
                Throw ex
            End Try

        End Function

        Public Shared Function ReportContactMethod(ByVal ContactMethod As String) As ReportDisplay
            Try
                If ContactMethod = "Outgoing Mail" Then
                    Return ReportDisplay.AddToOther
                ElseIf ContactMethod = "Other" Then
                    Return ReportDisplay.DontDisplay
                ElseIf ContactMethod = "NAR (No Action Required)" Then
                    Return ReportDisplay.DontDisplay
                ElseIf ContactMethod = "Unallocated" Then
                    Return ReportDisplay.DontDisplay
                Else
                    Return ReportDisplay.Display
                End If

            Catch ex As Exception
                Throw ex
            End Try
        End Function

        Public Shared Function NZStr(ByVal Item As String, ByVal ReplaceWith As String) As String
            Try
                If Item = vbNull Then
                    Return ReplaceWith
                Else
                    Return Item
                End If
            Catch ex As Exception
                Throw ex
            End Try
        End Function

        Public Shared Function NZint(ByVal Item As Int32, ByVal ReplaceWith As Int32) As Int32
            Try
                If Item = vbNull Then
                    Return ReplaceWith
                Else
                    Return Item
                End If
            Catch ex As Exception
                Throw ex
            End Try
        End Function

        Public Shared Function NZdbl(ByVal Item As Double, ByVal ReplaceWith As Double) As Double
            Try
                If Item = vbNull Then
                    Return ReplaceWith
                Else
                    Return Item
                End If
            Catch ex As Exception
                Throw ex
            End Try
        End Function
    End Class

End Namespace